#ifndef prs_TNodeSRule_H
#define prs_TNodeSRule_H

#include "sntText.h"
#include "svl_TNodeS.h"

namespace prs {

////////////////////////////////////////////////////////////////////////////////

struct TNodeSRule : public snt::TRule
{
/***********
  struct TObject : public svl::TObject
  {
    svl::TNode *Node;
    //
    TObject(svl::TNode *P) { Node = P;}
    //
    virtual svl::TObject *NewInstance()    { return new TObject(Node);}
    virtual void CopyFrom(svl::TObject *P) { Node = dynamic_cast<TObject*>(P)->Node;}
  };
************/
  snt::TRule    RLev;
  snt::TAlter   A1,A2,A3;
  svl::TVariant Name,Value,Node,This;
  //
  TNodeSRule(snt::text::TContext &Context,svl::TNodeS &OutNode)
  {
    This = this;
    Node = &OutNode;

    snt::text::TIdent     Ident(Context);
    snt::TFVoid           F;
    snt::text::TSequence  Seq(Context);
    snt::text::TString    Str(Context);
    snt::text::TEndOfText EndOfText(Context);
    snt::TReturn          Return;

    // this -> RLev -> EndOfText -> Return
    *this
    | RLev.New() & EndOfText.New() & Return.New()
    ;
    //        A1          A2               A3
    //        |<---------------------------|
    //        |           |--------------->|
    // RLev ->|-> Ident ->|-> '=' -> Str ->|-> Return
    //        |-> '{' -> RLev -> '}' ----->|
    RLev.Local(Node,Name)
    | A1.New()
    ;
    A1
    | Ident.New(Name) & F.New(&FName,Node,Name) & A2.New()
    | Seq.New("{") & F.New(&FL,This,Node) & RLev.New() &F.New(&FR,This,Node) & Seq.New("}") & A3.New()
    ;
    A2
    | Seq.New("=") & Str.New(Value) & F.New(&FValue,Node,Value) & A3.New()
    | A3.New()
    ;
    A3
    | A1.New()
    | Return.New()
    ;
  }
  //
  static void FName (snt::TParams &Params);
  static void FValue(snt::TParams &Params);
  static void FL    (snt::TParams &Params);
  static void FR    (snt::TParams &Params);
};

////////////////////////////////////////////////////////////////////////////////
}

#endif

